package ui.panels.primary.players;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JList;

import org.apache.log4j.Logger;

import ui.flowManager.expirimentProperties.ExperimentProperties;

/**
 * 
 * @author vladimir && alon
 *
 */
class KeyJList implements KeyListener
{
	private JList 					jlist = null;
	private PlayersPanel			playersPanel = null;
	private ExperimentProperties 	props = null;
	Logger log = Logger.getLogger(this.getClass());
	
	KeyJList(PlayersPanel panel, JList jlist, ExperimentProperties props)
	{
		this.playersPanel = panel;
		this.jlist = jlist;	
		this.props = props;
	}
	
	public void keyPressed(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void keyReleased(KeyEvent key) {
		// case Enter
		if(key.getKeyCode() == KeyEvent.VK_ENTER)
		{
			int index = jlist.getSelectedIndex();
			log.debug("Enter on control player " + index + 1);	 
			// call to function that do the rest
			playersPanel.executeListGame(jlist, index + 1);
		}
		// case Delete
		else if(key.getKeyCode() == KeyEvent.VK_DELETE)
		{
			int index = jlist.getSelectedIndex();
			log.debug("Delete on control player " + index + 1);
			//update the UI
			playersPanel.setTheListUI(index + 1, props);	
			//remove from props
			playersPanel.removeFromProperties(index + 1, props);
		}
	}

	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}
}
